﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using DBUtility;
using System.Data.SqlClient;
using System.Collections.Generic;

namespace dotnetsys
{
    public partial class Dataset_List : System.Web.UI.Page
    {
        protected DataSet ds = null;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            int pid = 100;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 10000  c.pid,pname,catalogid,bookid,sectionid,status,addtime,edittime,descript,clicks,c.orderby,t.content,");
            strSql.Append("(select top 1 pid from chapter where orderby<c.orderby and bookid=c.bookid order by orderby desc,pid desc) as prepid,(select top 1 pid from chapter where orderby>c.orderby and bookid=c.bookid order by orderby,pid) as nextpid");
            strSql.Append(" from Chapter c left join tContent t on c.pid=t.pid");
            strSql.Append("  ");
            //strSql.Append(bookid != -1 ? " and c.bookid=" + bookid : "");
            SqlParameter[] parameters = {
					new SqlParameter("@pid", SqlDbType.Int,4)
            };
            parameters[0].Value = pid;
            using (ds = DbHelperSQL.Query(strSql.ToString(), parameters))
            {
                Label1.Text = ds.Tables[0].Rows.Count + "";
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 10000  c.pid,pname,catalogid,bookid,sectionid,status,addtime,edittime,descript,clicks,c.orderby,t.content,");
            strSql.Append("(select top 1 pid from chapter where orderby<c.orderby and bookid=c.bookid order by orderby desc,pid desc) as prepid,(select top 1 pid from chapter where orderby>c.orderby and bookid=c.bookid order by orderby,pid) as nextpid");
            strSql.Append(" from Chapter c left join tContent t on c.pid=t.pid");
            List<Model.Chapter> list = new List<Model.Chapter>();
            using (SqlDataReader dr = DbHelperSQL.ExecuteReader(strSql.ToString(), null))
            {
                
                while (dr.Read())
                {
                    Model.Chapter mo = new Model.Chapter();
                    mo.pid = int.Parse(dr["pid"].ToString());
                    mo.pname = dr["pname"].ToString();
                    mo.descript = dr["descript"].ToString();
                    mo.content = dr["content"].ToString();

                    list.Add(mo);
                }
                dr.Close();
            }
            Label1.Text = list.Count + "";
        }
    }
}
